﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Xml;
using System.Xml.Linq;
namespace xmlMovie
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string ConString = ConfigurationManager.ConnectionStrings["ConStringTest"].ConnectionString;
                //string CMDString = "SELECT id,name,time, rating" + "FROM allMovie FOR XML RAW ('Movie'), ROOT('root'), ELEMENTS";
                string CMDString = " SELECT * FROM movie_test ";
                SqlConnection con;
                SqlCommand cmd;
                SqlDataAdapter sda;
                DataTable dt;


                using (con = new SqlConnection(ConString))
                {
                    cmd = new SqlCommand(CMDString, con);
                    con.Open();
                    dt = new DataTable("Movie");
                    sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt != null)
                    {
                        dt.WriteXml("C:\\Users\\Thao\\Desktop\\XML-ProJect\\xmlMovie\\xmlMovie\\App_Data\\haha.xml");
                    }
                    Label1.Text = "Dones";
                    con.Close();

                }

            }
            catch (Exception)
            {
                Label1.Text = "Fails";
            }
        }

        protected void data_Click(object sender, EventArgs e)
        {
            using (DataSet ds = new DataSet())
            {
                ds.ReadXml(Server.MapPath("~/App_Data/haha.xml"));
                GridView1.DataSource = ds;
                GridView1.DataBind();
                
            }
            
        }

        

      

       

        
    }
}
